<?php
namespace app\home\controller;
use app\home\controller;
use app\home\model\CheckStandardItemM;
use myResponse\Res;
use think\Db;
use think\Request;

//设备分类控制器
class CheckStandardItem extends Base{
    //显示分类列表

    function getList($page = 1,$size = 10,$StandardId = ''){
        $page *=1;
        $size *=1;
        $m= new CheckStandardItemM;
        $where='';
        if($StandardId && "undefined"!=$StandardId){
            $where['StandardId'] = $StandardId;
        }
        $z=$m->listP($page,$size,$where);
        Res::suc('ok',$z);
    }

    //添加设备分类
    function addOne(){
        //在CheckStandardItemModel里边通过一个指定方法实现权限添加
        $m= new CheckStandardItemM;
        $z=$m->addOne();
        if($z){
            Res::suc('添加成功！');
        }else {
            Res::errs('添加失败！');
        }
    }
    //修改
    function editOne(){
        //在CheckStandardItemModel里边通过一个指定方法实现权限添加
        $m= new CheckStandardItemM;
        $z=$m->editOne();
        if($z){
            Res::suc('修改成功！');
        }else {
            Res::errs('修改失败！');
        }

    }
    //复制项
    function copyOne(){
        //在CheckStandardModel里边通过一个指定方法实现权限添加
        $data = input('post.');
        unset($data['ItemId']);
        $data['Creator'] = session('user.UserId');
        $m = new CheckStandardItemM();
        // 过滤post数组中的非数据表字段数据
        $z = $m->allowField(true)->save($data);
        $id =$m->ItemId;
        if($id){
            Res::suc('复制成功！');
        }else {
            Res::errs('复制失败！');
        }

    }
    public function addMore($id=1){
        $it = new CheckStandardItemM();
//        $mp['StandardId'] = input('post.StandardId');
        $mp['StandardId'] = 1;
        $item = $it->where($mp)->select();
        $data=[];
        foreach ($item as $k => $v){
            $i['StandardId']=$id;
            $i['CheckPosition']=$v['CheckPosition'];
            $i['CheckContent']=$v['CheckContent'];
            $i['Param']=$v['Param'];
            $i['CheckJob']=$v['CheckJob'];
            $i['CycleTypeId']=$v['CycleTypeId'];
            $i['Sort']=$v['Sort'];
            $i['Creator']=$v['Creator'];
            $data[$k]=$i;
        }
        $res = $it->strict(false)->insertAll($data);
//        df($res);
    }
    //删除
    function delOne(){
        $m= new CheckStandardItemM;
        $z=$m->delOne(input('ItemId'));
        if($z){
            Res::suc('删除成功！');
        }else {
            Res::errs('删除失败！');
        }
    }
}
